/**
 * Copyright 2009 Adam Ruggles.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.google.code.sapien.service;

import com.google.code.sapien.exception.ServiceException;
import com.google.code.sapien.model.User;
import com.google.inject.ImplementedBy;

/**
 * Provides an interface for service operations on {@link com.google.code.sapien.model.User} entities.
 * @author Adam
 * @version $Id: UserService.java 20 2009-05-03 19:37:57Z a.ruggles $
 * 
 * Created on Feb 8, 2009 at 1:55:45 PM 
 */
@ImplementedBy(UserSapienService.class)
public interface UserService extends EntityService<User> {
	/**
	 * Persists the login for a given user.
	 * @param user A persistent user.
	 * @return An encrypted string containing the persistent login information.
	 * @throws ServiceException if an error occurs persisting the login.
	 */
	String addPersistentLogin(User user) throws ServiceException;

	/**
	 * Changes the password for a user.
	 * @param user The user.
	 * @param plain The plain text password.
	 */
	void changePassword(User user, String plain);

	/**
	 * Returns a {@link com.google.code.sapien.model.User} by email.
	 * @param email The email address.
	 * @return The {@link com.google.code.sapien.model.User} with the email or <code>null</code> if not found. 
	 */
	User getByEmail(String email);

	/**
	 * Returns a {@link com.google.code.sapien.model.User} by username.
	 * @param username The username.
	 * @return The {@link com.google.code.sapien.model.User} with the username or <code>null</code> if not found. 
	 */
	User getByUsername(String username);

	/**
	 * Returns a User from a encrypted persistent login message.  If successful a user will be returned and the 
	 * persistent login record will be deleted.
	 * @param encryptedMessage The encrypted message containing the persistent login information.
	 * @return A User if successful or null otherwise.
	 * @throws ServiceException If an error occurs decrypting the encrypted message.
	 */
	User getPersistentLogin(String encryptedMessage) throws ServiceException;

	/**
	 * Removes the persistent login. 
	 * @param encryptedMessage The encrypted message containing the persistent login information.
	 * @throws ServiceException
	 */
	void removePersistentLogin(String encryptedMessage) throws ServiceException;

	/**
	 * Validates the user's credentials.
	 * @param username The username.
	 * @param password The password.
	 * @return A user object if the user is valid, or null if it is not.
	 */
	User validate(String username, String password);
}
